home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmtime.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  4.2 KB  |  102 lines

  1. // CmTime.h
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Time class definition.
  7. // -----------------------------------------------------------------
  8.  
  9. #ifndef _CMTIME_H
  10. #define _CMTIME_H
  11.  
  12. #include <cm/include/cmdate.h>
  13.  
  14. class CmTime : public CmObject {              // Time class definition.
  15. public:
  16.   CmTime();                                   // Default time constructor.
  17.   CmTime(unsigned long s) : _sec(s) {}        // Construct from seconds.
  18.   CmTime(unsigned, unsigned, unsigned = 0);   // Construct from h, m, s.
  19.   CmTime(const CmDate&, unsigned = 0, unsigned = 0, unsigned = 0);
  20.  
  21.   Bool     isDST      () const;               // Check if daylight savings.
  22.   CmTime   localTime  () const;               // Get local time.
  23.   unsigned hour       () const;               // Get hour number.
  24.   unsigned hourGMT    () const;               // Get hour number (Greenwich).
  25.   unsigned minute     () const;               // Get minute number.
  26.   unsigned minuteGMT  () const;               // Get minute num  (Greenwich).
  27.   unsigned second     () const;               // Get second number.
  28.   void     makeCurrent();                     // Make this current time.
  29.  
  30.   unsigned long seconds() const;              // Returns seconds.
  31.  
  32.   operator CmDate() const;                    // Make date from time.
  33.  
  34.   Bool operator< (const CmTime&) const;       // Check if time <  this.
  35.   Bool operator<=(const CmTime&) const;       // Check if time <= this.
  36.   Bool operator> (const CmTime&) const;       // Check if time >  this.
  37.   Bool operator>=(const CmTime&) const;       // Check if time >= this.
  38.   Bool operator==(const CmTime&) const;       // Check if time == this.
  39.   Bool operator!=(const CmTime&) const;       // Check if time != this.
  40.  
  41.   Bool     isEqual(CmObject*) const;          // Compare times.
  42.   int      compare(CmObject*) const;          // Compare times.
  43.   unsigned hash   (unsigned)  const;          // Hash time.
  44.   void     printOn(ostream&)  const;          // Print time to stream.
  45.   Bool     write  (CmReserveFile&) const;     // Write time to file.
  46.   Bool     read   (CmReserveFile&);           // Read time from file.
  47.  
  48.   CMOBJECT_DEFINE(CmTime, CmObject)           // Define object funcs.
  49.  
  50.   static CmTime beginDST (unsigned);          // Get start of DST for year.
  51.   static CmTime endDST   (unsigned);          // Get end of DST for year.
  52.   static CmTime localTime(const CmDate&, unsigned = 0,  // Get local time.
  53.                            unsigned = 0, unsigned = 0);
  54.  
  55.   static void displayStyle(int);              // Set display style for all.
  56.   static int  displayStyle();                 // Get display style.
  57.  
  58.   enum display_style { DATE12, DATE24, NODATE12, NODATE24 };  // Styles.
  59.  
  60. private:
  61.   unsigned long _sec;                         // Seconds.
  62.   static   int  _displayStyle;                // Display style.
  63. };
  64.  
  65. // "seconds" returns the seconds value.
  66. inline unsigned long CmTime::seconds() const
  67. { return _sec; }
  68.  
  69. // "<" checks if the input is less than this time.
  70. inline Bool CmTime::operator<(const CmTime& T) const
  71. { return (_sec < T._sec); }
  72.  
  73. // "<=" checks if the input is less than or equal to this time.
  74. inline Bool CmTime::operator<=(const CmTime& T) const
  75. { return (_sec <= T._sec); }
  76.  
  77. // ">" checks if the input is greater than this time.
  78. inline Bool CmTime::operator>(const CmTime& T) const
  79. { return (_sec > T._sec); }
  80.  
  81. // ">=" checks if the input is greater than or equal to this time.
  82. inline Bool CmTime::operator>=(const CmTime& T) const
  83. { return (_sec >= T._sec); }
  84.  
  85. // "==" checks if the input is equal to this time.
  86. inline Bool CmTime::operator==(const CmTime& T) const
  87. { return (_sec == T._sec); }
  88.  
  89. // "!=" checks if the input is not equal to this time.
  90. inline Bool CmTime::operator!=(const CmTime& T) const
  91. { return (_sec != T._sec); }
  92.  
  93. // "displayStyle" sets the display style for all times.
  94. inline void CmTime::displayStyle(int ds)
  95. { CmTime::_displayStyle = ds; }
  96.  
  97. // "displayStyle returns the current display style.
  98. inline int CmTime::displayStyle()
  99. { return CmTime::_displayStyle; }
  100.  
  101. #endif
  102.